package net.cjw.initsb.controller.test;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import springfox.documentation.annotations.ApiIgnore;
import net.cjw.initsb.dao.ManageUserMapper;
import net.cjw.initsb.entity.ManageUser;
@ApiIgnore
@RestController
public class MybatisTestController {

	@Autowired
	private ManageUserMapper userinfoMapper;

	@GetMapping("mybatis")
	public String test() {

		ManageUser userinfo = userinfoMapper.selectByPrimaryKey("admin");
		if (userinfo == null) {
			return "找不到对象";
		}
		return userinfo.getNickname();
	}

	@GetMapping("pageHelper1")
	public Object test5() {
		PageHelper.startPage(0, 2);
		List<ManageUser> userinfos = userinfoMapper.selectAll();
		System.out.println("userinfos.size(): " + userinfos.size());

		// 取分页信息,包含分页页数等详细信息
		PageInfo<ManageUser> pageInfo = new PageInfo<ManageUser>(userinfos);
		System.out.println("pageInfo.getTotal(): " + pageInfo.getTotal()); // 获取总记录数

		return pageInfo;
	}

	@GetMapping("pageHelper2")
	public Object test6() {
		PageHelper.startPage(0, 2);
		List<ManageUser> userinfos = userinfoMapper.selectAll();
		System.out.println("userinfos.size(): " + userinfos.size());

		return userinfos;
	}

}
